# _*_ coding: UTF-8 _*_
# @Time     : 2021/2/19 下午 04:17
# @Author   : Li Jie
# @Site     : http://www.hzdledu.com/
# @File     : tcp_server.py
# @Software : PyCharm

import socket

host = '127.0.0.1'  # 服务器IP
port = 8888  # 服务器端口
serverSocket = socket.socket()  # 1.创建socket对象
serverSocket.bind((host, port))  # 2.绑定ip和port
serverSocket.listen(5)  # 3.开始监听，设置最大连接数为5
print('服务器端等待客户端连接...')
while True:  # 开启死循环
    clientSocket, addr = serverSocket.accept()  # 4.建立客户端连接
    data = clientSocket.recv(1024)  # 5.获取客户端请求数据
    print(data)  # 打印收到的数据
    clientSocket.sendall(b'HTTP/1.1 200 OK \r\n\r\nhello,this is www.hzdledu.com')  # 5.向客户端发送数据
    clientSocket.close()  # 6.关闭客户端连接
